package com.yaolonga.itfc.manager.core.utils;


import java.io.*;
import java.nio.charset.Charset;

/**
 * @Author: yaolong
 * @CreateTime: 2024-10-26  13:12
 * @Description: 流工具
 * @Version: 1.0
 */
public class StreamUtils {
    public static final int BUFFER_SIZE = 4096;

    public static String copyToString(InputStream in, Charset charset) throws IOException {
        if (in == null) {
            return "";
        }

        StringBuilder out = new StringBuilder(BUFFER_SIZE);
        InputStreamReader reader = new InputStreamReader(in, charset);
        char[] buffer = new char[BUFFER_SIZE];
        int charsRead;
        while ((charsRead = reader.read(buffer)) != -1) {
            out.append(buffer, 0, charsRead);
        }
        return out.toString();
    }
}
